package demo.pattern.proxy.cglib;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @ClassName AlipyMethodInterceptor
 * @Description
 * @Author 47980
 * @Date 2020/8/9 16:06
 * @Version V_1.0
 **/
public class AlipyMethodInterceptor implements MethodInterceptor {
    /**
     * 实现逻辑
     * @param o 被代理类实例
     * @param method 被代理类方法
     * @param objects 被代理类的参数
     * @param methodProxy 代理类的实例
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        beforePay();
        Object result = methodProxy.invokeSuper(o, objects);
        afterPay();
        return result;
    }

    private void beforePay() {
        System.out.println("从招行里取款");
    }

    private void afterPay() {
        System.out.println("支付给XXX");
    }
}
